/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import VO.CPulga;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Kyosuke
 */
public class CPulgaDAO {
    
     public boolean Insertar(CPulga pulga){
    boolean flag = false;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("EjercicioJPAPU"); 
    EntityManager em = emf.createEntityManager();
    EntityTransaction trans = em.getTransaction();
    
    trans.begin();
    try {
        em.persist(pulga);
        trans.commit();
        flag = true;
        
      }catch (Exception ex){
          trans.rollback();
      }finally{
        em.close();
    }
   
    return flag;
    }
        public boolean actualizar(CPulga pulga){
    boolean flag = false;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("EjercicioJPAPU"); 
    EntityManager em = emf.createEntityManager();
    EntityTransaction trans = em.getTransaction();
    
    trans.begin();
    try {
        em.merge(pulga);
        trans.commit();
        flag = true;
        
      }catch (Exception ex){
          trans.rollback();
      }finally{
        em.close();
    }
   
    return flag;
    }
            public boolean eliminar(CPulga pulga){
    boolean flag = false;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("EjercicioJPAPU"); 
    EntityManager em = emf.createEntityManager();
    EntityTransaction trans = em.getTransaction();
    
    trans.begin();
    try {
        em.remove(em.merge(pulga));
        trans.commit();
        flag = true;
        
      }catch (Exception ex){
          trans.rollback();
      }finally{
        em.close();
    }
   
    return flag;
    }
    
}
